#ifndef __SL811HST_H__
#define __SL811HST_H__

#include "core/include/types.h"

/* SL811hst Register map */
#define SL811_HOST_CONTROL_REGISTER_A	0x00
#define SL811_HOST_BASE_ADDRESS_A		0x01
#define SL811_HOST_BASE_LENGTH_A		0x02
#define SL811_HOST_PID_DDEVICE_EP_A		0x03
#define SL811_HOST_PID_USB_STATUS_A		0x03
#define SL811_HOST_DEVICE_ADDRESS_A		0x04
#define SL811_TRANSFER_COUNT_A			0x04
#define SL811_CONTROL_REGISTER_1		0x05
#define SL811_INT_ENABLE_REGISTER		0x06
#define SL811_HOST_CONTROL_REGISTER_B	0x08
#define SL811_HOST_BASE_ADDRESS_B		0x09
#define SL811_HOST_BASE_LENGTH_B		0x0A
#define SL811_HOST_PID_DDEVICE_EP_B		0x0B
#define SL811_HOST_PID_USB_STATUS_B		0x0B
#define SL811_HOST_DEVICE_ADDRESS_B		0x0C
#define SL811_TRANSFER_COUNT_B			0x0C
#define SL811_INT_STATUS_REGISTER		0x0D
#define SL811_SOF_COUNTER_LOW			0x0E
#define SL811_HW_REVISION_REGISTER		0x0E
#define SL811_SOF_COUNTER_HIGH			0x0F
#define SL811_CONTROL_REGISTER_2		0x0F
#define SL811_MEMORY_BUFFER_BASE_ADR	0x10


/* 0x00, 0x08 : HOST Control Register */
#define bPREAMBLE						0x80
#define bDATA_TOGGLE					0x40
#define bDATA_0							0x00
#define bDATA_1							0x40
#define bSYNC_SOF						0x20
#define bISO							0x10
#define bDIRECTION						0x04
#define bENABLE							0x02
#define bARM							0x01


/* 0x03, 0x0B : Host PID, Endpoint (write) */
#define PID_SETUP						(0x0D << 4)
#define PID_IN							(0x09 << 4)
#define PID_OUT							(0x01 << 4)
#define PID_SOF							(0x05 << 4)
#define PID_PREAMBLE					(0x0C << 4)
#define PID_NAK							(0x0A << 4)
#define PID_STALL						(0x0E << 4)
#define PID_DATA0						(0x03 << 4)
#define PID_DATA1						(0x0B << 4)

#define bEP3							0x08
#define bEP2							0x04
#define bEP1							0x02
#define bEP0							0x01


/* 0x03, 0x0B : USB Packet Status (Read) */
#define SL811_STALL						0x80
#define SL811_NAK						0x40
#define SL811_OVERFLOW					0x20
#define SL811_SETUP						0x10
#define SL811_SEQUENCE					0x08
#define SL811_TIME_OUT					0x04
#define SL811_ERROR						0x02
#define SL811_ACK						0x01


/* 0x05 : Control Register */
#define bSUSPEND						0x40
#define bUSB_SPEED						0x20
#define bJ_K_STATE_FORCE				0x10
#define bUSB_ENGINE_RESET				0x08
#define bSOF_ENABLE_DISABLE				0x01
#define bSOF_ENABLE						0x01
#define bSOF_DISABLE					0x00


/* 0x06 : Intrrupt Enable Register */
#define bDMA_STATUS						0x80
#define bUSB_RESET						0x40
#define bSOF_RECEIVED					0x20
#define bDMA_DONE						0x10
#define bEP3_DONE						0x08
#define bEP2_DONE						0x04
#define bEP1_DONE						0x02
#define bEP0_DONE						0x01


/* 0x0D : Intrrupt Status Register */
#define bD_PLUS							0x80
#define bDEV_DETECT_REUSME				0x40
#define bINSERT_REMOVE					0x20
#define bSOF_TIMER						0x10
#define bUSB_B							0x02
#define bUSB_A							0x01


/* 0x0F : Control Register 2 */
#define bMASTER_SLAVE_SELECT			0x80
#define bMASTER_SELECTED				0x80
#define bSLAVE_SELECTED					0x00
#define bPOLARITY_SWAP					0x40


/* system def */
#define USB_ACK						0x01
#define USB_NACK					0x02
#define USB_STALL					0x04


/* ------ SL811 Device Driver ------ */
void SL811_USB_Reset(void);
BYTE SL811HST_deviceCheck(void);
BYTE SL811_getSpeed(void);
BYTE SL811_SETUP_transaction(BYTE speed, BYTE usbAdr, BYTE EPx, BYTE *setupPacket, WORD len);
BYTE SL811_IN_transaction(   BYTE speed, BYTE usbAdr, BYTE EPx, BYTE dataX, BYTE *buf, WORD len);
BYTE SL811_OUT_transaction(  BYTE speed, BYTE usbAdr, BYTE EPx, BYTE dataX, BYTE *buf, WORD len);

#endif/*__SL811HST_H__*/
